package model;

import java.util.*;

public class GameModel {
	/** Mapping from a position to a player model. 
	 * Current supported position names: NORTH, SOUTH.
	 */
	private Map<Position, PlayerModel> players;
	private TableModel tableModel;
	public GameModel() {
		players = new HashMap<Position, PlayerModel>();
		tableModel = new TableModel();
		players.put(Position.NORTH, new PlayerModel());
		players.put(Position.SOUTH, new PlayerModel());
		
	}

	public ArrayList<CardStack> getTableCards() {
		return tableModel.getCardStacks();
	}
	public ArrayList<Card> getPlayerHand(Position pos) {
		return players.get(pos).getCards();
	}
	public String getPlayerName(Position pos) {
		return players.get(pos).getName();
	}
	public TableModel getTable() {
		return tableModel;
	}
	public PlayerModel getPlayer(Position pos) {
		return players.get(pos);
	}
	
	public void moveToHand(CardStack tableStack, int numSelected, Position pos)
	{
		PlayerModel player = players.get(pos);
		for (int i =0; i < numSelected; i++)
			player.addCard(tableStack.pop());
		
		if(tableStack.size()==0)
			tableModel.getCardStacks().remove(tableStack);
	}
	
	public void moveFromHand(Set<Card> selection, Position pos, CardStack toStack)
	{
		PlayerModel player = players.get(pos); // TODO generalize
		
		for(Card card : selection) {
			player.removeCard(card);
			toStack.push(card);
		}
	}
	
}
